package com.ruoyi.project.pm.common.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.project.pm.common.domain.PMInfoVO;
import com.ruoyi.project.pm.common.domain.SalesCustomerVO;
import com.ruoyi.project.pm.common.service.PMCommonService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author 铁蛋儿
 * @date 2020-09-19 16:50
 * @desc 百战程序员 http://www.itbaizhan.com
 *
 * 公共控制器  主要是用于各个功能模块都会用到的  查看项目详细信息的功能
 *
 */
@Controller
@RequestMapping("/pm/common")
public class PMCommonController extends BaseController {

    //前缀字符串
    String prefix = "/pm/common";

    @Autowired
    PMCommonService pmCommonService;

    /**
     * 查看项目的详细信息 并根据传递回来的pmId查询需要的数据
     */
    @RequiresPermissions("pm:common:viewinfo")
    @GetMapping("/viewinfo/{pmId}")
    public String edit(@PathVariable("pmId") Integer pmId, Model model) throws Exception {
        System.out.println("pmId=" + pmId);
        if (pmId == null) {
            throw new Exception("网络丢失......");
        }
        PMInfoVO pmInfoVO = pmCommonService.selectPMInfoVOById(pmId);
        System.out.println("pmInfoVO=" + pmInfoVO);
        Integer csId = pmInfoVO.getCsId();
        SalesCustomerVO salesCustomerVO = pmCommonService.selectSalesCustomerVOById(csId);
        System.out.println("SalesCustomerVO=" + salesCustomerVO);

        model.addAttribute("pmInfoVO", pmInfoVO);
        model.addAttribute("salesCustomer",salesCustomerVO);
        return prefix + "/viewinfo";
    }


}
